<?php

/**
 * Форма настроек
 */
class SettingsForm extends Zend_Form {

    /**
     * Возвращает форму настроек
     *
     * @return SettingsForm
     */
    public function MainSettings() {
        $t = Zend_Registry::get('Zend_Locale');
        $this->setName('group');
        $title = new Zend_Form_Element_Text('title');
        $title->setLabel('Site title')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $slogan = new Zend_Form_Element_Text('slogan');
        $slogan->setLabel('Site slogan')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $time = new Zend_Form_Element_Text('time');
        $time->setLabel('Time format')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty')
                ->setRequired();

        $model = new PageModel();
        $template = new Zend_Form_Element_Select('template');
        $templates = $model->getAddons('template');
        foreach ($templates as $key => $value) {
            $options[$value->title] = $value->name;
        }
        $template->addMultiOptions($options)
                ->setLabel('Template')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty')
                ->setRequired();

        $lang = new Zend_Form_Element_Select('lang');
        $languages = $model->getAddons('language');
        foreach ($languages as $key => $value) {
            $language[$value->title] = $value->name;
        }
        $lang->addMultiOptions($language)
                ->setLabel('Language')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty')
                ->setRequired();

        $count_per_page = new Zend_Form_Element_Text('count_per_page');
        $count_per_page->setLabel('Count per page')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $pass_lenght = new Zend_Form_Element_Text('pass_lenght');
        $pass_lenght->setLabel('Password lenght')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $pages_list = $model->getPagesList();
        if (!is_array($pages_list))
            $pages_list = array('0' => $t->_('Empty'));
        $page404 = new Zend_Form_Element_Select('page404');
        $page404->addMultiOptions($pages_list)
                ->setLabel('404 page')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        /* ============================ADMIN=================================== */

        $files = new Zend_Form_Element_Text('files');
        $files->setLabel('Files')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty')
                ->setRequired();

        $model = new AclModel();
        $groups = $model->getGroupsList();
        $group = new Zend_Form_Element_Select('group');
        $group->addMultiOptions($groups)
                ->setLabel('Default group')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty')
                ->setRequired();

        $group_registered = new Zend_Form_Element_Select('group_registered');
        $group_registered->addMultiOptions($groups)
                ->setLabel('Registered group')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty')
                ->setRequired();

        $etrace = new Zend_Form_Element_Checkbox('etrace');
        $etrace->setLabel('Debug')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        /* ============================ПОЧТА=================================== */

        $smtp_email = new Zend_Form_Element_Text('smtp_email');
        $smtp_email->setLabel('E-mail')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $smtp_server = new Zend_Form_Element_Text('smtp_server');
        $smtp_server->setLabel('SMTP server')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $smtp_login = new Zend_Form_Element_Text('smtp_login');
        $smtp_login->setLabel('Login')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $smtp_password = new Zend_Form_Element_Text('smtp_password');
        $smtp_password->setLabel('Password')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $smtp_name = new Zend_Form_Element_Text('smtp_name');
        $smtp_name->setLabel('Sender name')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $secure = array('0' => $t->_('Empty'), 'tls' => 'TLS', 'ssl' => 'SSL');
        $smtp_ssl = new Zend_Form_Element_Select('smtp_ssl');
        $smtp_ssl->setLabel('Secure type')
                ->addMultiOptions($secure)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $smtp_port = new Zend_Form_Element_Text('smtp_port');
        $smtp_port->setLabel('Secure port')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Save');
        $submit->setAttrib('id', 'submitbutton');


        $this->addElements(array($title, $slogan, $template, $lang, $time, $count_per_page, $pass_lenght, $page404, $files, $group, $group_registered, $etrace, $smtp_email, $smtp_name, $smtp_server, $smtp_login, $smtp_password, $smtp_ssl, $smtp_port, $submit));

        $this->addDisplayGroup(array('title', 'slogan', 'template', 'lang', 'time', 'count_per_page', 'pass_lenght', 'page404'), 'settings', array('legend' => $t->_('Main settings')));
        $this->addDisplayGroup(array('files', 'group', 'group_registered', 'etrace'), 'administration', array('legend' => $t->_('Administration settings')));
        $this->addDisplayGroup(array('smtp_name', 'smtp_email', 'smtp_server', 'smtp_login', 'smtp_password', 'smtp_ssl', 'smtp_port', 'submit'), 'mail', array('legend' => $t->_('Mail settings')));

        $this->setDisplayGroupDecorators(array(
            'FormElements',
            'Fieldset'
        ));

        $this->setAction('');
        $this->setDefaultTranslator($t);
        return $this;
    }

}